<template>
	<div class="role" v-if="dialogFormVisible">
		<el-dialog :title="title" :visible="dialogFormVisible"
				   width="800px" top="5vh"
				   :close-on-click-modal="false"
				   :before-close="handleClose"
				   append-to-body>
			<div class="tab">
				<el-form ref="form" :rules="rules" :model="form" label-width="80px">
					<el-form-item label="测试结果" prop="result">
						<el-radio-group v-model="form.result">
							<el-radio label="Pass"></el-radio>
							<el-radio label="Fail"></el-radio>
							<el-radio label="Block"></el-radio>
							<el-radio label="Skip"></el-radio>
							<el-radio label="N/A"></el-radio>
						</el-radio-group>
					</el-form-item>
					<el-form-item label="备注" prop="remark" :rules="form.result != 'Pass' ? rules.remark : [{required: false}]">
						<el-input v-model="form.remark" :rows="6" type="textarea" placeholder="请输入备注"></el-input>
					</el-form-item>
				</el-form>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="handleClose">取 消</el-button>
				<el-button type="primary" @click="add('form')">提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import { taskCasePost, bugId } from '@/api/user'
export default {
	name: 'addForm',
	components:{

	},
	data(){
		return {
			dialogFormVisible:false,
			form:{

			},
			id:'',
			rules:{
				result:[{required: true, message: '请选择测试结果', trigger: 'change' }],
				remark: [
					{max: 500, message: '备注不能超过500个字符', trigger: 'blur'},
					{ required: true, message: '请输入备注', trigger: 'blur' }]
			},
			title:'结果填写',
			fatherId:''
		}
	},
	created() {
	},
	methods:{
		handleClose(){
			this.dialogFormVisible = false
			this.form = {}
		},
		add(form){
			this.$refs[form].validate((valid) => {
				let obj = {
					result:this.form.result,
					remark:this.form.remark
				}
				if (valid) {
					this.dialogFormVisible = false
					taskCasePost(obj,this.id).then(res => {
						if(res.status == 'success'){
							this.$message.success('填写成功！')
							// this.$parent.initTable()

							this.$emit('func',this.fatherId)
							this.form = {}
						} else if(res.code == 403){
							this.$message.error('无权限操作！')
						} else {
							this.$message.error('填写错误！')
							this.dialogFormVisible = false
							this.form = {}
						}
					})
				} else {
					return false;
				}
			});
		},
		initData(data,id){
			this.id = data.id
			this.fatherId = id
			this.form = Object.assign({},data)
		}
	}

}
</script>

<style lang="scss" scoped>
.role{

}
.step{
	margin: 10px 0;
}
.testCase{
	margin-top: 22px;
	border-top: 1px solid #eee;
	padding-top: 10px;
	height: 430px;
	overflow:scroll;
}
.testTable{
	height: 430px;
	overflow:scroll;
}
.del{
	color: #1890FF;
	cursor: pointer;
}
</style>
